/*
2022-2-27 
https://www.acwing.com/problem/content/4309/
*/
#include<cstring>
#include<iostream>
#include<algorithm>

using namespace std;
int a[3010];

int main()
{
    int n;
    cin>>n;
    for(int i=0;i<n;i++) 
        cin>>a[i];
    sort(a,a+n);
    int ans=0;
    for(int i=0;i<n-1;i++)
    {
        if(a[i+1]<=a[i]) 
        {
            ans+=a[i]-a[i+1]+1;
            a[i+1]=a[i]+1;
        }
    }
    
    cout<<ans<<endl;
    
    return 0;
}
